package dongshi.daddy.provider;

import dongshi.daddy.api.UserRpcService;
import dongshi.daddy.provider.service.UserRpcServiceImpl;
import org.apache.dubbo.config.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Scanner;

public class ProviderApplication {
    private static final Logger logger = LoggerFactory.getLogger("provider_ProviderApplication");
    public static void main(String[] args) {
        logger.info("provider initialize by api begin");
        // 当前应用配置
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("user-service-provider11191458");
        // 连接注册中心配置
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setProtocol("zookeeper");
        registryConfig.setAddress("127.0.0.1:2181");
        // 服务提供者协议配置
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(20881);
        protocolConfig.setThreads(101);

        // 暴露服务
        ServiceConfig<UserRpcService> serviceConfig = new ServiceConfig<>();
        serviceConfig.setApplication(applicationConfig);
        serviceConfig.setRegistry(registryConfig); // 设置注册地址
        serviceConfig.setProtocol(protocolConfig); // 设置协议
        serviceConfig.setInterface(UserRpcService.class);
        serviceConfig.setRef(new UserRpcServiceImpl()); // 设置具体实现类
        serviceConfig.export(); // 完成暴露
        logger.info("provider initialize by api end");
        new Scanner(System.in).next();

    }
}
